package mousemove;

import java.awt.Color;
import java.awt.Graphics;


public abstract class Sprite
{
	protected double currentX, currentY;
	protected double increX, increY;
	
	protected int speed;
	protected int destX, destY;
	protected int width, height;
	
	protected boolean isMoving;
	protected Color color;
	
	protected Sprite(int x, int y ,int v)
	{
		currentX = x;
		currentY = y;
		speed = v;
		color = Color.DARK_GRAY;
	}
	
	public void move()
	{
		if (!arrived())
		{
			currentX += increX;
			currentY += increY;
		}
	}
	
	protected boolean arrived()
	{
		return Math.abs(destX - currentX) < width && Math.abs(destY - currentY) < height;
	}
	
	public void setDestination(int x, int y)
	{
		isMoving = true;
		destX = x;
		destY = y;
		increX = destX - currentX;
		increY = destY - currentY;
		
		if (Math.abs(increX) < Math.abs(increY))
		{
			increX = increX*speed/Math.abs(increY);
			increY = Integer.signum((int)increY)*speed;
		}
		else
		{
			increY = increY*speed/Math.abs(increX);
			increX = Integer.signum((int)increX)*speed;
		}
	}

	public abstract void draw(Graphics g);
}
